package com.tencent.yolov5ncnn;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jiangdg.ausbc.utils.ToastUtils;
import com.jiangdg.demo.R;

import java.util.List;

public class MyAdapter extends BaseQuickAdapter<ReportBean, BaseViewHolder> {
    public MyAdapter(@Nullable List<ReportBean> data) {
        super(R.layout.item_record, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, ReportBean reportBean) {
        holder.setText(R.id.etLabel, reportBean.label);
        holder.setText(R.id.tvCount, reportBean.realCount + "");
        holder.setText(R.id.etExpCount, reportBean.expectCount + "");
        Button btnSave = holder.getView(R.id.btnSave);
        EditText etLabel = holder.getView(R.id.etLabel);
        EditText etExpCount = holder.getView(R.id.etExpCount);
        btnSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String label = etLabel.getText().toString();
                String expCount = etExpCount.getText().toString();
                if(TextUtils.isEmpty(label)||TextUtils.isEmpty(expCount)){
                    ToastUtils.show("检测目标或期望个数不能为空");
                    return;
                }
                reportBean.label = label;
                reportBean.expectCount = Integer.valueOf(expCount);
                notifyDataSetChanged();

            }
        });

    }
}
